package image;

import org.junit.Test;
import utils.ZipUtils;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author hujian
 * @Date 2021/12/30 19:52
 * @Description 图片压缩测试
 */
public class ImageCompress {

    @Test
    public void testCompress() {
        String filePath = "C:\\Users\\40138\\Desktop\\test222\\1100000312708111-38-285\\";
        List<File> fileList = new ArrayList<>();
        try {
            Files.list(Paths.get(filePath))
                    .filter(path -> path.getFileName().toString().endsWith("jpg"))
                    .forEach(path -> {
                        fileList.add(new File(path.toString()));
                    });
            System.out.println("photo number:" + fileList.size());
            FileOutputStream fos2 = new FileOutputStream(new File("C:\\Users\\40138\\Desktop\\test222\\1100000312708111-38-285\\mytest.zip"));
            ZipUtils.toZip(fileList, fos2);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Test
    public void testDepress() {
        String zipFilePath = "C:\\Users\\40138\\Desktop\\test222\\1100000312708111-38-285\\mytest.zip";
        String outputFolder = "C:\\Users\\40138\\Desktop\\test222\\1100000312708111-38-285\\test3";
        System.out.println(new File(zipFilePath).exists());
        ZipUtils.unZipIt(zipFilePath, outputFolder);

        //测试2
//        try {
//            ZipUtils.upZipFile(new File(zipFilePath), outputFolder);
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
    }


}
